package com.jushu.storbox.entities;

import java.io.Serializable;
import java.util.Calendar;

import android.content.ContentValues;
import android.database.Cursor;
import android.view.View;

import com.jushu.storbox.constant.Constant;
import com.jushu.storbox.database.IBaseDao;
import com.jushu.storbox.task.tqueue.UploadTask;
import com.huawei.sharedrive.sdk.android.modelV2.response.FileInfoResponseV2;
import com.huawei.sharedrive.sdk.android.modelV2.response.FolderResponse;
import com.huawei.sharedrive.sdk.android.modelV2.response.INodeShareV2;

/**
 * cloud drive FileInformation data
 * 
 */
public class FileFolderInfo extends ResourceEntity implements Serializable, Cloneable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1302864360175592167L;

	private String parent;
	
	private transient View itemView;

	private byte type;

	private String name;

	private String description;

	private long size;

	private String version;

	private String status;

	private String md5 = null;
	
	private String localIdentity = "";

	private String etag;

	private String sha1 = null;

	private long createdAt;

	private long modifiedAt;

	private String createdBy;

	private String modifiedBy;

	private long contentCreatedAt;

	private long contentModifiedAt;

	private boolean isShare;

	private boolean isSync;

	private boolean isSharelink;

	private int isFile;

	private int isUpload;

	private boolean isEncrypt;
	private int transStatus;
	/**
	 * server and client compare 0：init 1：server exist，client not exist，New 2：server exist，client exist，md5 is not same,content changed
	 */
	private int state = Constant.SYNC_STATUS_TRUE;

	private String loctPath;
	
	private String musicPath;

	private String sharedId;//

	private String sharedOwnerName;

	private long sharedUserId;

	private String sharedUserType;

	private String sharedUserName;

	private String sharedOwnerId;

	private String sharedUserLoginName;

	private String sharedDepartment;

	private String sharedRoleName;

	/** upload callback */
	private transient UploadTask uploadTask;
	
	private long lastRefreshTime;

	private long operationTime;

	private long localLastModifyTime;

	/**
	 * nodeID
	 */
	private String iNodeId;

	private String ownerName;
	
	private String toleName;
	
	private String shareDepartment;
	
	private String roleName;
	
	private String thumbnailURL;
	
	private String currentProgress;
	
	private String currentSize;
	
	private String objectID;
	
	private int lastUpdateDate;
	
	private int isInode = -1;
	
	private int progress = 0;
	
	private String currentUserId;
	
	private String teamSpaceId;	
	public int getIsInode() {
		return isInode;
	}

	public void setIsInode(int isInode) {
		this.isInode = isInode;
	}

	public int getLastUpdateDate() {
		return lastUpdateDate;
	}

	public void setLastUpdateDate(int lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}

	public String getObjectID() {
		return objectID;
	}

	public void setObjectID(String objectID) {
		this.objectID = objectID;
	}

	public String getCurrentProgress() {
		return currentProgress;
	}

	public void setCurrentProgress(String currentProgress) {
		this.currentProgress = currentProgress;
	}

	public String getCurrentSize() {
		return currentSize;
	}
	
	public void setProgress(int progress) {
		this.progress = progress;
	}

	public int getProgress() {
		return progress;
	}

	public void setCurrentSize(String currentSize) {
		this.currentSize = currentSize;
	}
	
	public String getSharedId() {
		return sharedId;
	}

	public void setSharedId(String sharedId) {
		this.sharedId = sharedId;
	}

	public long getSharedUserId() {
		return sharedUserId;
	}

	public void setSharedUserId(long sharedUserId) {
		this.sharedUserId = sharedUserId;
	}

	public String getSharedUserType() {
		return sharedUserType;
	}

	public void setSharedUserType(String sharedUserType) {
		this.sharedUserType = sharedUserType;
	}

	public String getSharedUserName() {
		return sharedUserName;
	}

	public void setSharedUserName(String sharedUserName) {
		this.sharedUserName = sharedUserName;
	}

	public String getSharedUserLoginName() {
		return sharedUserLoginName;
	}

	public void setSharedUserLoginName(String sharedUserLoginName) {
		this.sharedUserLoginName = sharedUserLoginName;
	}

	public String getSharedDepartment() {
		return sharedDepartment;
	}

	public void setSharedDepartment(String sharedDepartment) {
		this.sharedDepartment = sharedDepartment;
	}

	public String getSharedRoleName() {
		return sharedRoleName;
	}

	public void setSharedRoleName(String sharedRoleName) {
		this.sharedRoleName = sharedRoleName;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMd5() {
		return md5;
	}

	public String getLocalIdentity() {
		return localIdentity;
	}

	public void setLocalIdentity(String localIdentity) {
		this.localIdentity = localIdentity;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public String getEtag() {
		return etag;
	}

	public void setEtag(String etag) {
		this.etag = etag;
	}
	
	public String getIdentity() {
		if(md5 != null) {
			return md5;
		} else if(sha1 != null) {
			return sha1;
		} else {
			return null;
		}
	}
	
	public String getSha1() {
		return sha1;
	}

	public void setSha1(String sha1) {
		this.sha1 = sha1;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public String getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public boolean isShare() {
		return isShare;
	}

	public void setShare(boolean isShare) {
		this.isShare = isShare;
	}

	public boolean isSync() {
		return isSync;
	}

	public void setSync(boolean isSync) {
		this.isSync = isSync;
	}

	public boolean isSharelink() {
		return isSharelink;
	}

	public void setSharelink(boolean isSharelink) {
		this.isSharelink = isSharelink;
	}

	public boolean isEncrypt() {
		return isEncrypt;
	}

	public void setEncrypt(boolean isEncrypt) {
		this.isEncrypt = isEncrypt;
	}

	public int getIsFile() {
		return isFile;
	}

	public void setIsFile(int isFile) {
		this.isFile = isFile;
	}

	public int getIsUpload() {
		return isUpload;
	}

	public void setIsUpload(int isUpload) {
		this.isUpload = isUpload;
	}

	public String getLoctPath() {
		return loctPath;
	}

	public void setLoctPath(String loctPath) {
		this.loctPath = loctPath;
	}

	/**
	 * @return 
	 * {@link Constant.SYNC_STATUS_TRUE}</br>
	 * {@link Constant.SYNC_STATUS_FALSE}</br>
	 */
	public int getContentSyncState() {
		return state;
	}

	/**
	 * @param state</br>
	 * {@link Constant#SYNC_STATUS_TRUE}</br>
	 * {@link Constant#SYNC_STATUS_FALSE}</br>
	 */
	public void setContentSyncState(int state) {
		this.state = state;
	}

	public long getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(long createdAt) {
		this.createdAt = createdAt;
	}

	public long getModifiedAt() {
		return modifiedAt;
	}

	public void setModifiedAt(long modifiedAt) {
		this.modifiedAt = modifiedAt;
	}

	public long getContentCreatedAt() {
		return contentCreatedAt;
	}

	public void setContentCreatedAt(long contentCreatedAt) {
		this.contentCreatedAt = contentCreatedAt;
	}

	public long getContentModifiedAt() {
		return contentModifiedAt;
	}

	public void setContentModifiedAt(long contentModifiedAt) {
		this.contentModifiedAt = contentModifiedAt;
	}

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public UploadTask getUploadTask() {
		return uploadTask;
	}

	public void setUploadTask(UploadTask uploadTask) {
		this.uploadTask = uploadTask;
	}

	public int getTransStatus() {
		return transStatus;
	}

	public void setTransStatus(int transStatus) {
		this.transStatus = transStatus;
	}

	public long getOperationTime() {
		return operationTime;
	}

	public void setOperationTime(long operationTime) {
		this.operationTime = operationTime;
	}

	public long getLocalLastModifyTime() {
		return localLastModifyTime;
	}

	public void setLocalLastModifyTime(long localLastModifyTime) {
		this.localLastModifyTime = localLastModifyTime;
	}

	public String getSharedOwnerName() {
		return sharedOwnerName;
	}

	public void setSharedOwnerName(String sharedOwnerName) {
		this.sharedOwnerName = sharedOwnerName;
	}

	public String getSharedOwnerId() {
		return sharedOwnerId;
	}

	public void setSharedOwnerId(String sharedOwnerId) {
		this.sharedOwnerId = sharedOwnerId;
	}

	public long getLastRefreshTime() {
		return lastRefreshTime;
	}

	public void setLastRefreshTime(long lastRefreshTime) {
		this.lastRefreshTime = lastRefreshTime;
	}

	public String getiNodeId() {
		return iNodeId;
	}

	public void setiNodeId(String iNodeId) {
		this.iNodeId = iNodeId;
	}

	public String getOwnerName() {
		return ownerName;
	}

	public void setOwnerName(String ownerName) {
		this.ownerName = ownerName;
	}

	public String getToleName() {
		return toleName;
	}

	public void setToleName(String toleName) {
		this.toleName = toleName;
	}

	public String getShareDepartment() {
		return shareDepartment;
	}

	public void setShareDepartment(String shareDepartment) {
		this.shareDepartment = shareDepartment;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getThumbnailURL() {
		return thumbnailURL;
	}

	public void setThumbnailURL(String thumbnailURL) {
		this.thumbnailURL = thumbnailURL;
		//+ ClientConfig.THUMBNAIL_SIZE);
	}

	public View getItemView() {
		return itemView;
	}

	public void setItemView(View itemView) {
		this.itemView = itemView;
	}
	
	public void setMusicPath(String path){
		this.musicPath=path;
	}
	
	public String getMusicPath(){
		return musicPath;
	}

	public String getCurrentUserId() {
		return currentUserId;
	}

	public void setCurrentUserId(String currentUserId) {
		this.currentUserId = currentUserId;
	}
	
	public void valueOf(FileInfoResponseV2 fileInfo){
		setId(fileInfo.getId());
		setOwnerId(fileInfo.getOwnerBy());
		setParent(fileInfo.getParent());
	}
	
	public void valueOf(FolderResponse fileInfo) {
		setId(fileInfo.getId());
		setOwnerId(fileInfo.getOwnerBy());
		setParent(fileInfo.getParent());
	}

	public void valueOf(INodeShareV2 fileInfo) {
		setId(fileInfo.getNodeId().toString());
		setOwnerId(fileInfo.getOwnerId().toString());
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}
	
	//id is unique diffrence on file and folder in userspace
	@Override
	public boolean equals(Object o) {
		if(o == null) {//x.equals(null) == true
			return false;
		}
		if(this == o) {//x.equals(x) == true
			return true;
		}
		if(o instanceof FileFolderInfo) {
			FileFolderInfo obj = (FileFolderInfo) o;
			if(getId().equals(obj.getId()) && getOwnerId().equals(obj.getOwnerId())) {//other recipe
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		if(getId() != null && getOwnerId() != null) {
			return getId().hashCode() + getOwnerId().hashCode();
		} else {
			return super.hashCode();
		}
	}

	public String getTeamSpaceId() {
		return teamSpaceId;
	}

	public void setTeamSpaceId(String teamSpaceId) {
		this.teamSpaceId = teamSpaceId;
	}

	public void fromCursor(Cursor cursor) {
	}
	
	public ContentValues toContentValues() {
		return new ContentValues();
	}
	
	public ContentValues getIdentityCV() {
		return new ContentValues();
	}
	
	public ContentValues getSyncStateCV() {
		ContentValues cv = new ContentValues();
		cv.put(IBaseDao.content_sync_status, getContentSyncState());
		cv.put(IBaseDao.local_last_modify_time, Calendar.getInstance().getTimeInMillis());
		return cv;
	}
	
}
